package com.code.day05;

public class Ticket1 implements Runnable {
    static int ticket = 100;
    @Override
    public void run() {
        for(;;)
        {
            try{
                Thread.sleep(100L);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            method();
            if(ticket == 0){
                return;
            }
        }
    }
    public static void method(){
        synchronized (Ticket1.class){
            if(ticket > 0){
                System.out.println(Thread.currentThread().getName() + "....买了第" + ticket-- + "张票");
            }
        }
    }
    public static synchronized void method1(){
        if(ticket > 0){
            System.out.println(Thread.currentThread().getName() + "....买了第" + ticket-- + "张票");
        }
    }
}
